/*
export function someMutation (state) {
}
*/

export const APPEND_LIST = (statue, list) => {
  statue.infoList.push(...list)
}

export const CLEAN_LIST = (statue) => {
  statue.infoList = []
}

export const SET_CUR_INFO = (statue, info) => {
  statue.curInfo = info
}

export const REMOVE_CUR_INFO = (statue) => {
  statue.curInfo = {}
}

export const MY_LIST = (statue, list) => {
  // 我们要对list进行排序，按照获奖时间从大到小排
  list.sort((a, b) => new Date(b.date) - new Date(a.date))
  statue.myList = list
}

// 竞赛列表也应该支持时间设置，这样就能排序了
export const SET_COMP_CATE = (statue, list) => {
  statue.cateList = list
}

export const SET_MSG_BOX = (statue, compList) => {
  statue.relatedComp = compList
}

export const UPDATE_RELATED_LIST = (statue, info) => {
  // 找到对应的comp将其替换掉 如果状态已经变了 就应该删除了
  for (let i = 0; i < statue.relatedComp.length; i += 1) {
    const c = statue.relatedComp[i]
    if (c.pk === info.pk) {
      if (info.all_accept) {
        delete statue.relatedComp[i]
      } else {
        statue.relatedComp[i] = info
      }
      break
    }
  }
}

export const ADD_RELATED_LIST = (statue, info) => {
  statue.relatedComp.push(info)
}
